<?php

/* Usage
    $noError = 1;
    $messenger = new Messenger();
    if($noError)
    {
        $messenger->setMessageType(1); // -1 error, 1 success (default type is -1)
        $messenger->addMessage("Datos Personales Guardados exitosamente.");
        $messenger->addMessage("Datos Personales Guardados muy exitosamente.");
        $messenger->addMessage("Datos Personales Guardados muy muy exitosamente.");
    }
    else
    {
        $messenger->addMessage("ERROR al guardar los Datos Personales: ". mysql_error());
    }

    // Need number of messages?
    echo "Number of Messages: ". $messenger->countMessages()

    // Showing messages 1:
    $messenger->showMessages();

    // Showing messages 2:
    $messages = $messenger->getMessages();
    echo $messages;
*/
class Messenger
{
	public $_messagesType; // -1 error, 0 standby, 1 success
	public $_arMessages = array();

    public function __construct($type=-1)
    {
        $this->setMessageType($type);
    }

    public function addMessage($msg)
    {
		if (!trim($msg) ) return;
        array_push($this->_arMessages, $msg);
    }

    public function setMessageType($type)
    {
        $this->_messagesType = $type;
    }

    public function countMessages()
    {
        return count($this->_arMessages);
    }

	public function getMessages()
	{
        if (count($this->_arMessages)>0)
        {
            switch($this->_messagesType)
            {
                case  1:  $out ="<div class=\"messageSuccess\"><ul>"; break;
                case  0:  $out ="<div class=\"messageStandBy\"><ul>"; break;
                case -1: $out ="<div class=\"messageFailure\"><ul>"; break;
            }
            foreach($this->_arMessages AS $msg)
            {
                $out .= "<li>". $msg ."</li>";
            }
            $out .="</ul></div>\n";
        }
        return $out;
	}

	public function getArMessages()
	{
		return $this->_arMessages;
	}
	
	public function getMessagesType()
	{
		return $this->_messagesType;
	}
	
	public function showMessages()
	{
	    echo $this->getMessages();
    }
}

?>
